
from common.db import BaseModel
from django.db import models
# django自带的认证表
from django.contrib.auth.models import AbstractUser

class User(AbstractUser,BaseModel):
    mobile = models.CharField(verbose_name="手机号",default='',max_length=11)
    class Meta:
        db_table = 'users'
        verbose_name = '用户表'

class DisordersType(models.Model):
    type_name = models.CharField(verbose_name="类型名称",default='',max_length=20)
    class Meta:
        db_table = 'disorders_type'
        verbose_name = '障碍类型表'

class UserData(BaseModel):
    medical_record_num = models.CharField(verbose_name="病历号", default='', max_length=50)
    user_name = models.CharField(verbose_name="姓名", default='', max_length=16)
    age = models.CharField(verbose_name="年龄", default='', max_length=6)
    gender = models.CharField(verbose_name="性别", default='', max_length=4)
    height = models.CharField(verbose_name="身高", default='', max_length=6)
    weight = models.CharField(verbose_name="体重", default='', max_length=6)
    pulse = models.CharField(verbose_name="脉搏", default='', max_length=6)
    blood_pressure = models.CharField(verbose_name="血压", default='', max_length=6)
    start_time = models.CharField(verbose_name="起始时间", default='', max_length=16)
    disorders_type = models.CharField(verbose_name="障碍类型", default='', max_length=4)
    allergy_history = models.CharField(verbose_name="过敏史", default='', max_length=255)
    past_history = models.CharField(verbose_name="既往史", default='', max_length=255)
    hpi = models.CharField(verbose_name="现病史", default='', max_length=255)
    user_id = models.CharField(verbose_name="用户id",default='', max_length=20)
    class Meta:
        db_table = 'user_data'
        verbose_name = '用户信息表'


class Questionnaire(models.Model):
    disorders_type = models.CharField(verbose_name="障碍类型", default='', max_length=4)
    question = models.CharField(verbose_name="问题描述", default='', max_length=255)
    class Meta:
        db_table = 'questionnaire'
        verbose_name = '问卷调查主表'

class QuestionItem(models.Model):
    issue_select = models.CharField(verbose_name="问卷选项", default='', max_length=255)
    score = models.CharField(verbose_name="问卷分数", default='', max_length=4)
    question_id = models.CharField(verbose_name="问卷主表ID", default='', max_length=4)
    class Meta:
        db_table = 'question_item'
        verbose_name = '问卷调查子表'


class ScoreResult(models.Model):
    user_data_id = models.CharField(verbose_name="用户详情表ID", default='', max_length=20)
    question_result = models.CharField(verbose_name="问卷结果", default='', max_length=255)
    total_score = models.CharField(verbose_name="总评分", default='', max_length=10)
    total_score_result = models.CharField(verbose_name="评分结果", default='', max_length=255)
    disorders_type = models.CharField(verbose_name="障碍类型", default='', max_length=4)
    class Meta:
        db_table = 'score_result'
        verbose_name = '评分结果表'


class EmgData(models.Model):
    user_data_id = models.CharField(verbose_name="用户详情表ID", default='', max_length=20)
    average_emg = models.CharField(verbose_name="平均肌电值", default='', max_length=20)
    median_frequency = models.CharField(verbose_name="中位频率值", default='', max_length=20)
    variation_coefficient = models.CharField(verbose_name="变异系数", default='', max_length=20)
    up_down_time = models.CharField(verbose_name="上升/下降时间", default='', max_length=20)
    class Meta:
        db_table = 'emg_data'
        verbose_name = '肌电数据采集'

"""
文献指南 知识库
"""
class LiteratureKnowledge(models.Model):
    two_type = models.CharField(verbose_name="二便障碍类型", default='', max_length=20)
    symptoms = models.CharField(verbose_name="症状/严重程度", default='', max_length=20)
    contraindications = models.CharField(verbose_name="禁忌症", default='', max_length=20)
    prescription_type = models.CharField(verbose_name="处方类型", default='', max_length=20)
    details  = models.CharField(verbose_name="处方详情", default='', max_length=255)
    class Meta:
        db_table = 'literature_knowledge'
        verbose_name = '文献指南 知识库'

"""
磁刺激处方知识库  MagneticStimulusPrescriptions
"""
class MagneticStimulusPrescriptions(models.Model):
    indication = models.CharField(verbose_name="适应症", default='', max_length=50)
    protocol_name = models.CharField(verbose_name="方案名称", default='', max_length=100)
    stimulation_site = models.CharField(verbose_name="刺激部位", default='', max_length=50)
    frequency = models.CharField(verbose_name="频率", default='', max_length=20)
    stimulation_duration = models.CharField(verbose_name="刺激时间（秒）", default='', max_length=20)
    interval_duration = models.CharField(verbose_name="间歇时间（秒）", default='', max_length=20)
    number_of_series = models.CharField(verbose_name="串数", default='', max_length=20)
    rest_duration   = models.CharField(verbose_name="休息时间（秒）", default='', max_length=20)
    class Meta:
        db_table = 'magnetic_stimulus_prescriptions'
        verbose_name = '磁刺激处方知识库'

""""
电刺激处方  ElectricalStimulusPrescriptions 
"""
class ElectricalStimulusPrescriptions(models.Model):
    category = models.CharField(verbose_name="分类", default='', max_length=50)
    name = models.CharField(verbose_name="名称", default='', max_length=50)
    stimulation_time = models.CharField(verbose_name="刺激时间", default='', max_length=20)
    rest_time = models.CharField(verbose_name="休息时间", default='', max_length=20)
    rise_time = models.CharField(verbose_name="上升时间", default='', max_length=20)
    fall_time = models.CharField(verbose_name="下降时间", default='', max_length=20)
    stimulation_frequency = models.CharField(verbose_name="刺激频率", default='', max_length=20)
    pulse_width  = models.CharField(verbose_name="脉冲宽度", default='', max_length=20)
    class Meta:
        db_table = 'electrical_stimulus_prescriptions'
        verbose_name = '电刺激处方知识库'


"""
病人案例， 还未将model和表联系起来
"""

class PatientCase(models.Model):
    # 患者id，使用IntegerField或PositiveIntegerField，因为ID通常是整数
    patient_id = models.IntegerField(verbose_name="患者id", unique=True)
    
    # 问题得分，使用IntegerField，因为得分通常是整数
    score1 = models.IntegerField(verbose_name="问题1得分", default=0)
    score2 = models.IntegerField(verbose_name="问题2得分", default=0)
    score3 = models.IntegerField(verbose_name="问题3得分", default=0)
    score4 = models.IntegerField(verbose_name="问题4得分", default=0)
    
    # 前静息阶段平均值，使用FloatField
    qianjinxi_avg = models.FloatField(verbose_name="前静息阶段平均值")
    
    # 快肌阶段-最大值，使用FloatField
    kuaiji_max = models.FloatField(verbose_name="快肌阶段-最大值")
    
    # 快肌阶段-上升时间，使用FloatField
    kuaiji_up = models.FloatField(verbose_name="快肌阶段-上升时间")
    
    # 快肌阶段-恢复时间，使用FloatField
    kuaiji_recover = models.FloatField(verbose_name="快肌阶段-恢复时间")
    
    # 慢肌-平均值，使用FloatField
    manji_avg = models.FloatField(verbose_name="慢肌-平均值")
    
    # 慢肌-变异性，使用FloatField
    manji_var = models.FloatField(verbose_name="慢肌-变异性")
    
    # 慢肌-上升时间，使用FloatField
    manji_up = models.FloatField(verbose_name="慢肌-上升时间")
    
    # 慢肌-恢复时间，使用FloatField
    manji_recover = models.FloatField(verbose_name="慢肌-恢复时间")
    
    # 耐力测试-平均值，使用FloatField
    naili_avg = models.FloatField(verbose_name="耐力测试-平均值")
    
    # 耐力测试-变异性，使用FloatField
    naili_var = models.FloatField(verbose_name="耐力测试-变异性")
    
    # 耐力测试-后前10s比值，使用FloatField
    naili_rate = models.FloatField(verbose_name="耐力测试-后前10s比值")
    
    # 后静息-平均值，使用FloatField
    houjingxi_avg = models.FloatField(verbose_name="后静息-平均值")
    
    # 后静息-变异性，使用FloatField
    houjingxi_var = models.FloatField(verbose_name="后静息-变异性")

    class Meta:
        db_table = 'patient_case'  # 数据库中已有的表名
        managed = False  # 禁止 Django 自动管理该表（即不自动创建、删除该表）
    def __str__(self):
        return f"Patient {self.patient_id} Case"
    